<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/back/layuiadmin/layui/css/layui.css"  media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>

<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script>
    $.ajax({
        async:true,
        type:"GET",
        url:"${pageContext.request.contextPath}/back/saleData5",
        dataType:"json",
        success:function (result) {
            console.log(result);
            var content="";
            content=content+"<option value=\"全部\">全部</option>"
            $.each(result,function (index,data) {
                console.log(index+data.auditoriumsName)
                content=content+"<option value=\""+data.auditoriumsName+"\">"+data.auditoriumsName+"</option>";

            })
            $("#auditoriumsName").html(content);
        },
        error:function() {
            alert("异步处理失败");
        }
    })
</script>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto" style="height: 50px;">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">影厅</label>
                    <div class="layui-input-inline">
                        <select  id="auditoriumsName">
                            <option value="全部">全部</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">电影名</label>
                    <div class="layui-input-inline">
                        <input type="text" name="accountName" placeholder="请输入" autocomplete="off" class="layui-input"id="filmName">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">起止时间</label>
                    <div class="layui-input-inline">
                        <input type="text"  id="test6" placeholder=" 起时间-止时间 "class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="search" id="serch">
                    <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                </button>
            </div>
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="export" id="export">
                        <i class="layui-icon layui-icon-export  layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>
        <div class="layui-card-body">
            <table class="layui-hide" id="test" lay-filter="test"></table>
        </div>
    </div>
</div>

<script src="${pageContext.request.contextPath}/back/layuiadmin/layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script>
    layui.config({
        base: '${pageContext.request.contextPath}/back/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['table','laydate','form'], function(){
        var table = layui.table;
        form = layui.form,
        $ = layui.$;

        var clos=[[
            {type:'numbers', title:'id', unresize: true, sort: true ,fixed: 'left'}
            ,{field:'auditoriumsName', title:'影厅',templet: '<div>{{d.screening.auditoriums.auditoriumsName}}</div>'}
            ,{field:'filmName', title:'电影名',templet:'<div>{{d.screening.film.filmName}}</div>'}
            ,{field:'screeningStartTime', title:'时间', sort: true,templet:'<div>{{d.screening.screeningStartTime}}</div>'}
            ,{field:'salesCount', title:'销售量', sort: true,templet:'<div>{{d.salesCount}}</div>'}
            ,{field:'salesPrice', title:'收入',sort:true,templet:'<div>{{d.salesPrice}}</div>'}
            ,{field:'attendance', title:'上座率',width:120,sort:true,templet:function (data) {
                    var num=new Number(data.salesCount/100);
                    var num1=num.toFixed(2);
                    var num2=num1*100;
                    var num3=num2+"%";
                    return num3
                }}
                    // '<div>{{(d.salesCount/500)}}</div>'}
        ]];
        table.render({
            elem: '#test'
            ,url: '${pageContext.request.contextPath}/back/saleData' //数据接口
            ,cellMinWidth: 80
            ,title: '统计数据表'
            ,cols: clos
            ,page: true
            ,parseData:function(res){
                console.log(res)

                return {
                    "code": 0, //解析接口状态
                    "msg": "搜索成功", //解析提示文本
                    "count": res.total, //解析数据长度
                    "data": res.list, //解析数据列表
                };
            }
        });



        $("#export").click(function () {

            var page=1;
            var limit=99999999;

            var filmName=$("#filmName").val();
            var screeningStartTime=$("#test6").val();
            // 分割
            var screeningStartTime1=screeningStartTime.substring(0,10);
            var screeningStartTime2=screeningStartTime.substring(13);
            var auditoriumsName=$("#auditoriumsName option:checked").text();
            location.href="${pageContext.request.contextPath}/back/export?page="+
            page+"&limit="+limit+"&filmName="+
            filmName+"&screeningStartTime1="+screeningStartTime1+"&screeningStartTime2="+screeningStartTime2+"&auditoriumsName="+auditoriumsName;
        })



    $("#serch").click(function () {
            console.log($(".layui-laypage-limits select").val());


                var filmName=$("#filmName").val();

                var screeningStartTime=$("#test6").val();
                // 分割
                console.log(screeningStartTime.substring(0,10));
               console.log(screeningStartTime.substring(13));
              var screeningStartTime1=screeningStartTime.substring(0,10);
                 var screeningStartTime2=screeningStartTime.substring(13);


                var auditoriumsName=$("#auditoriumsName option:checked").text();
                console.log(auditoriumsName);

            var field={

                    filmName:filmName,
                    screeningStartTime1:screeningStartTime1,
                    screeningStartTime2:screeningStartTime2,
                auditoriumsName:auditoriumsName};


        table.render({
                elem: '#test'
                ,url: '${pageContext.request.contextPath}/back/saleData' //数据接口
                ,cellMinWidth: 80
                ,title: '统计数据表'
                ,cols:clos
                ,where: field
                ,page: true
                ,parseData:function(result) {
                    console.log(result)
                    return {
                        "code": 0, //解析接口状态
                        "msg": "搜索成功", //解析提示文本
                        "count": result.total, //解析数据长度
                        "data": result.list, //解析数据列表
                    }
                }

            });

            });

    });


    layui.use('laydate', function(){
        var laydate = layui.laydate;

        //日期范围
        laydate.render({
            elem: '#test6'
            ,range: true
        });
    })








</script>

</body>
</html>